<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<%@ include file="/commons/commonEdit.jsp" %>
<%@ include file="/commons/validation.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/public3.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/pages/com/ce/pms/occupation/occupation.js"></script>
<script  type="text/javascript">
var submitFormName="ownerForm";
var str = "";
var otherStr = "";
function radioClickHandle(tableid,displayable){
	display(tableid,displayable);
}
function choiceHouse(){
	var url = "${ctx}/customer_chooseSingleHouseAction.do?method=chooseBuildingMain";
	top.windowOpen(url, "choiceHouse", "", 500, 800);
}
function setHouseInfo(houseId,houseNum){
		document.getElementById("houseId").value = houseId;
		document.getElementById("houseNumber").value = houseNum;
		$('houseNumber').fireEvent("onblur");
}
//房屋验证后成功后调用的方法,验证成功了,则添加房屋ID到 houseid
function houseSuccessHandle(result){
	$('houseId').value = result.responseText;
	ajaxSearchHouseInfo();
}
function ajaxSearchHouseInfo(){
	var url = "${ctx}/occupation_joinHandleAction.do?method=queryCustomerHouse";
	var houseId = $F('houseId');
	$('houseNumber').setAttribute("oldHouseNumber",houseId);
	if(houseId == "")
		return;
	var param = "houseId="+houseId;
	new Ajax.Request(url,{method: 'post', parameters: param, onComplete: showResponse});
}
function showResponse(result){
	var selfHouseNumber = $F('houseNumber');
	var obj= eval("("+result.responseText+")");
	if(selfHouseNumber == $('houseNumber').getAttribute("oldHouseNumber")){
		return false;
	}
	if("false" == result.responseText){
		Alert("没有业主请重新选择!");
		$('houseNumber').value="";
		$('houseId').value="";
		resetLoad();
		return false;
	}
	resetLoad();
	$('houseNumber').setAttribute("oldHouseNumber",selfHouseNumber);
	str = "";
	otherStr = "";
	var isFirst = true;
	for(var i = 0; i < obj.length;i++){
		var realhouseInfo = "";
	    if(isFirst && obj[i].coalitionHouseNumber.length>0){
	    	$('otherHouseInfo').deleteRow();
	    	$('otherHouseInfo').deleteRow();
			isFirst = false;
	    }
	    var re = /#@/g;
	    realhouseInfo = obj[i].realHouseClientInfo.replace(re,"&nbsp;");
		if(obj[i].houseNumber == selfHouseNumber.toUpperCase() ){
		    str = str+buildClientInfo(obj[i].houseNumber,obj[i].coalitionHouseNumber,obj[i].realHouseClientInfo);
			var tempStr = obj[i].ownerName.split(",");
			for(var j=0;j<tempStr.length;j++)
				loadClient(tempStr[j]);
			$('coalitionHouseNumber').innerText=obj[i].coalitionHouseNumber;
			$('ownerSelf').innerHTML= $('ownerSelf').innerHTML+realhouseInfo+" <br>";
		}else{
       		otherStr = otherStr+buildClientInfo(obj[i].houseNumber,obj[i].coalitionHouseNumber,obj[i].realHouseClientInfo);
			fillOtherHouseInfo(obj[i].houseNumber,realhouseInfo);
		}
	}
	if(isFirst){
		$('joinMode').disabled=true;
	}else{
		$('joinMode').disabled=false;
	}
}
function resetLoad(){
    $('ownerSelf').innerHTML = "";
	$('clientId').innerHTML = "";
	$('coalitionHouseNumber').innerText="";
    var rowss = $('otherHouseInfo').rows;
    var len = rowss.length;
    for(var i = 0 ; i <len;i++){
		$('otherHouseInfo').deleteRow();
	}
	$('joinMode').checked = false;
	fillOtherHouseInfo("","");
}
function addIdentity(){
    setTimeout("mysubmit()",2000);
}
function mysubmit(){
	var isChoose = $('tempForm').fireEvent("onSubmit");
	var isTrue=$(submitFormName).fireEvent("onSubmit") ;
    if(isTrue && isChoose){
       document.getElementById('sumitok').disabled = true;
       if(submitFormName == "ownerForm"){
       		$(submitFormName).clientName.value=getClientName();
       }else{
       		$(submitFormName).clientName.value=$F('consignAgentName');
       }
       var tempMode = "001";
       $(submitFormName).clientInfo.value=str;
       if($('joinMode').checked){
       		tempMode="002";
       		$(submitFormName).clientInfo.value=str+otherStr;
       }

       var param = Form.serialize(submitFormName);
       param = param+"&houseId="+$F('houseId')+"&houseNumber="+$F('houseNumber')+"&joinMode="+tempMode;
       var url = "${ctx}/occupation_joinHandleAction.do?method=addIdentityValidate";
       new Ajax.Request(url,{method: 'post',parameters :param ,onSuccess : showResult});
	}
}
function setConsignTypeName(thiz){
	var index = thiz.selectedIndex;
	$('consignAgentIdTypeName').value = thiz.options[index].text;
}
function showResult(response){
	if(response.responseText == "true"){
		var obj=findFrame('identityMain');
		obj.reloadIdentity();
		windowClose();
    }else{
		document.getElementById('sumitok').disabled = false;
    	ajaxSubmitException(response.responseText);
    }

}
function setFlag(flagVar){
	submitFormName = flagVar;
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle" /> <span class="window_head_intext">身份验证新增</span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td valign="middle" class="content"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="container_in_show">
      <tr>
        <td valign="top">
            <div id="tab_Search">
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab_subMenu1">
                      <tr>
                        <td>
						<div style="height:360px;overflow:auto">
						<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
                            <tr>
                              <td><table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color" >
                                  <tr>
                                    <td valign="top" class="aux_intable_td1">房 号：</td>
                                    <td valign="top" class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td><input type="hidden" name="houseId" value=""></td>
                                          <td></td>
                                        </tr>
                                        <form name="tempForm" action="" class="required-validate">
                                        <tr>
                                          <td>
                                          		<input name="houseNumber" type="text" class="required validate-ajax"  value="" size="16"
                                          				validateUrl="${ctx}/occupation_joinHandleAction.do?method=validationHouseNumber"
                                          				returnIsTrue="false"
                                          				validateMessage="该房号不存在"
                                          				onkeydown="if(event.keyCode==13)return false;"
                                          				onSuccess="houseSuccessHandle"
                                          				afterInsert="bdAfter"/>
                                          </td>
                                          <td width="4">&nbsp;</td>
                                          <td><a href="#"  onClick="choiceHouse();"onFocus="this.blur()"><img src="${ctx}/images/ico_houesno.GIF" alt="请点选查找房号" border="0" /></a><span id="bdAfter"></span></td>
                                        </tr>
                                        </form>
                                    </table></td>
                                  </tr>
									<tr>
										<td valign="top" class="aux_intable_td1">业 主：</td>
			 							<td valign="middle" class="aux_intable_td2" id="ownerSelf"></td>
									  </tr>
								  <tr>
                                    <td colspan="2" class="aux_titletable">管理房号:<span id="coalitionHouseNumber"></span>&nbsp;&nbsp;&nbsp;
                                      <input name="joinMode" type="checkbox" value="002">
                                      <span style="font-weight:normal"> 按管理房办理</span>
                                    </td>
							     </tr>
							     <tbody id="otherHouseInfo" >
							      </tr>
									    <td valign="top" class="aux_intable_td1">相关房号：</td>
				                        <td valign="top" class="aux_intable_td2"></td>
									 </tr>
									<tr>
										<td valign="top" class="aux_intable_td1">业 主： </td>
										<td valign="top" class="aux_intable_td2"></td>
									</tr>
								 </tbody>
								 <tr>
                                    <td class="aux_titletable">入伙人信息：</td>
                                    <td class="aux_intable_require">&nbsp;<input name="radioRoom" type="radio" value="radiobutton" checked="checked"  onClick="radioClickHandle('table01','show');radioClickHandle('table02','hidden');setFlag('ownerForm')" />
                                      业 主&nbsp;　&nbsp;　&nbsp;　&nbsp;　&nbsp;　
                                      <input type="radio" name="radioRoom" value="radiobutton" onClick="radioClickHandle('table02','show');radioClickHandle('table01','hidden');setFlag('consignForm')" />
                                      委托代理人</td>
								  </tr>
                                 </table>
                                 <form action="" name="ownerForm" method="post" class="required-validate">
                                  <input type="hidden" name="clientName" value="">
                                  <input type="hidden" name="clientInfo" value="">
                                  <input type="hidden" name="transactJoinIdentity" value="001">
                                  <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color" id="table01" style="display:show">
                                    <tr>
                                      <td class="aux_intable_td1">业主姓名：</td>
                                      <td class="aux_intable_require" id="clientId">
					               		<span id="bdAfter"></span>
                                      </td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="aux_intable_td1">备 注：</td>
                                      <td class="aux_intable_td2"><textarea name="description" id="desr1" cols="29" rows="3" class="max-length-200"></textarea></td>
                                    </tr>
                                  </table>
                                  </form>
                                  <form action="" name="consignForm" method="post" class="required-validate">
                                  <input type="hidden" name="transactJoinIdentity" value="002">
                                  <input type="hidden" name="clientName" value="">
                                  <input type="hidden" name="clientInfo" value="">
                                  <input type="hidden" name="consignAgentIdTypeName" value="">
                                <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color" id="table02" style="display:none">
                                    <tr>
                                      <td class="aux_intable_td1">委托代理人姓名：</td>
                                      <td class="aux_intable_require"><input name="consignAgentName" type="text" class="required validate-char" size="16" maxlength="36"/>                                      </td>
                                    </tr>
                                    <tr>
                                      <td class="aux_intable_td1">证件类型：</td>
                                      <td class="aux_intable_require">
                                        <pms:unitedSelect id="orgcertificateType"
										name="consignAgentIdTypeId" dataList="${certificateTypeList}" selectText="请选择..."
								 		optionLabel="idTypeName"
								 		onChange="setConsignTypeName(this)"
								 		className="select-one-required"
										optionValue="idTypeId">
									  </pms:unitedSelect></td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="aux_intable_td1">证件号码：</td>
                                      <td class="aux_intable_require">
                                        <input name="consignAgentIdNumber" type="text" class="required validate-char" size="16" maxlength="30" />
                                      </td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="aux_intable_td1">联系电话：</td>
                                      <td class="aux_intable_td2"><table border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td><input name="consignAgentLinkmanPhone" type="text" class="validate-char" size="16" maxlength="30"/></td>
                                          <td width="4">&nbsp;</td>
                                          <td>&nbsp;</td>
                                        </tr>
                                      </table></td>
                                    </tr>
                                    <tr>
                                      <td valign="top" class="aux_intable_td1">备 注：</td>
                                      <td class="aux_intable_td2"><textarea name="description" id="desr2" cols="29" rows="2" class="max-length-200"></textarea></td>
                                    </tr>
                                </table>
                                </form>
                                </td>
                            </tr>
                        </table>
						</div>
						</td>
                      </tr>
                  </table></td>
                </tr>
              </table>
            </div></td>
        </tr>
       </table></td>
  </tr>
<tr>
    <td class="window_footer"><table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td class="btn_between_space"></td>
          <td><table id="sumitok" border="0" cellpadding="0" cellspacing="0" onclick="addIdentity()" >
            <tr>
              <td class="buttonOffLeft" id="btn1_51"></td>
              <td class="buttonOffMiddle" id="btn1_52" onblur="btn_change(5)" onMouseOver="btn_change_over(5)" onMouseOut="btn_change_out(5)" ><img src="${ctx}/images/ico_ok.gif" border="0" align="absmiddle" /> 保 存</td>
              <td class="buttonOffRight" id="btn1_53"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0" onClick="windowClose();">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onblur="btn_change(3)" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"><img src="${ctx}/images/ico_cancel.gif" border="0" align="absmiddle" /> 关 闭</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table>
	</td>
</tr>
</table>
</body>
</html>